<template>
  <div  class="layout" :class="{'layout-hide-text': spanLeft < 5}" v-loading="spinShow">
    <!--<Back-top ></Back-top>-->
    <Row  type="flex">
      <Col  :span="spanLeft" class="layout-menu-left">
        <leftmenu ></leftmenu>
      </Col>
      <Col :span="spanRight" :class="tright">
        <div style="height: 100%">
          <rightspan @toggleClick="toggleClick" @ChangePwd="ChangePwd"></rightspan>
          <div class="layout-content">
            <div class="layout-content-main">
              <Back-top ></Back-top>
              <transition name="fade" mode="out-in">
                <router-view></router-view>
              </transition>
            </div>
          </div>
        </div>
      </Col>
    </Row>
    <Modal
      title="公告"
      v-model="showPass"
      @on-ok="asyncOK">
      <i-form ref="formPass" :model="formPass" :rules="formPassRules">
        <Form-item label="旧密码" prop="oldPwd">
          <Input type="password" v-model="formPass.oldPwd" placeholder="旧密码">
          <Icon type="ios-locked-outline" slot="prepend"></Icon>
          </Input>
        </Form-item>
        <Form-item label="新密码" prop="newPwd">
          <Input type="password" v-model="formPass.newPwd" placeholder="新密码">
          <Icon type="ios-locked-outline" slot="prepend"></Icon>
          </Input>
        </Form-item>
        <Form-item label="重复密码" prop="repeatPwd">
          <Input type="password" v-model="formPass.repeatPwd" placeholder="重复密码">
          <Icon type="ios-locked-outline" slot="prepend"></Icon>
          </Input>
        </Form-item>
      </i-form>
    </Modal>
  </div>
  <!-- 修改密码 模态框 -->

  <!-- 修改密码 模态框 -->
</template>

<script>
  import {mapActions, mapState} from 'vuex'
  import api from './api'
  import leftmenu from './components/layout/leftMenu.vue'
  import rightspan from './components/layout/rightspan.vue'
  export default {
    name: 'app',
    data () {
      return {
        modeType: "vertical",
        spinShow: false,//数据刷新遮罩层
        spanLeft: 3,
        spanRight: 21,
        logoIsDisplay: false,
        rightStyle: "layout-right",
        photo: "../assets/default.jpg",
        formPass: {
          oldPwd: '',
          newPwd: '',
          repeatPwd: ''
        },
        formPassRules: {
          oldPwd: [
            {required: true, message: '请填写密码', trigger: 'blur'},
            {type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur'}
          ],
          newPwd: [
            {required: true, message: '请填写密码', trigger: 'blur'},
            {type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur'}
          ],
          repeatPwd: [
            {required: true, message: '请填写密码', trigger: 'blur'},
            {type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur'}
          ],
        },
        showPass:false
      }
    },
    components: {
      leftmenu,
      rightspan
    },
    computed: {
      ...mapState(['menuNeeded', 'msg', 'isLogin', 'userprof', 'isLoginPage']),
      tright(){
        if (!this.menuNeeded) {
          this.spanLeft = 0
          this.spanRight = 24
          return "layout-right-toggle"
        } else {
          return "layout-right"
        }
      },
    },
    watch: {
      // 如果 userprof 发生改变，这个函数就会运行
      isLogin(){
        if(this.isLogin){
          this.spanLeft = 3
          this.spanRight = 21
          this.rightStyle = "layout-right"
          this.getUserInfo()
        }else{
          this.rightStyle = "layout-right-toggle"
          this.spanLeft = 0
          this.spanRight = 24
        }
      }
//      userprof() {
//        this.welcom()
//      }
    },
    methods: {
      ...mapActions(['getUserInfo']),
      toggleClick () {
          console.log(this.menuNeeded)
        if (this.menuNeeded) {
          this.rightStyle = "layout-right"
          this.spanLeft = 3
          this.spanRight = 21
        } else {
          this.rightStyle = "layout-right-toggle"
          this.spanLeft = 0
          this.spanRight = 24
        }
        console.log(this.spanRight)
//        this.toggle=this.getToggle
//        this.toggle = !this.toggle
      },
      ChangePwd(){
        this.showPass=true
      },
      asyncOK () {
        this.$refs['formPass'].validate((valid) => {
          if (valid) {
            api.ChangePwd(this.formPass).then(response => {
              if (response.data.code != 0) {
                this.$Message.error(this.msg, 4)
              }else{
                this.$Message.success(this.msg, 4)
              }

            }, err => {
              this.$Message.error(this.msg, 4)
            })
          } else {
            this.$Message.error('表单验证失败!')
          }
        })
      },
    },
    mounted(){
//      this.welcom()
      this.$Notice.config({
        top: 60,
        duration: 3
      });
      if(this.isLogin){
        this.getUserInfo()
      }

    }
  }
</script>


<style>
  .fade-enter-active, .fade-enter {
    -webkit-animation: moveFromRight .5s both ease;
    animation: moveFromRight .5s both ease;
  }

  .fade-leave-to, .fade-leave-active {
    -webkit-animation: moveToLeft 1s both ease;
    animation: moveToLeft 1s both ease;
  }

  .layout-padding {
    padding: 1em 4em;
  }

  @media screen and (max-width: 600px) {
    .layout-padding {
      padding: 1.5em .5em;
    }
  }

  .menu-enter-active, .scale-enter {
    -webkit-animation: moveFromLeftFade .9s ease both;
    animation: moveFromLeftFade .9s ease both;
  }

  .menu-leave-to, .scale-leave-active {
    -webkit-animation: moveToLeft .9s ease both;
    animation: moveToLeft .9s ease both;
  }

  @-webkit-keyframes moveFromLeftFade {
    from {
      opacity: 0.3;
      -webkit-transform: translateX(-100%);
    }
  }

  @keyframes moveFromLeftFade {
    from {
      opacity: 0.3;
      -webkit-transform: translateX(-100%);
      transform: translateX(-100%);
    }
  }

  @-webkit-keyframes moveToRight {
    from {
    }
    to {
      -webkit-transform: translateX(100%);
    }
  }

  @keyframes cartOut {
    from {
      transform: translate(0px, 0px);
    }
    to {
      transform: translate(1200px, 0px);
      animation-timing-function: ease-out;
    }

  }

  @-webkit-keyframes moveToLeft {
    from {
    }
    to {
      opacity: .5;
      -webkit-transform: translateX(-100%);
    }
  }

  @keyframes moveToLeft {
    from {
    }
    to {
      opacity: .5;
      -webkit-transform: translateX(-100%);
      transform: translateX(-100%);
    }
  }

  @-webkit-keyframes moveFromRight {
    from {
      opacity: .7;
      -webkit-transform: translateX(100%);
    }
  }

  @keyframes moveFromRight {
    from {
      opacity: .7;
      -webkit-transform: translateX(100%);
      transform: translateX(100%);
    }
  }

  .drawer-closer .item-content {
    margin-left: 50px !important;
  }

  .drawer-content .list-label {
    line-height: 45px;
  }

  .drawer-content .item {
    height: 45px;
  }

  .router-link-active .item-primary {
    color: #027be3;
  }

  .q-picker-textfield .q-picker-textfield-label {
    color: inherit !important;
  }

  .label-success .q-picker-textfield-label {
    color: #4caf50 !important;
  }

  .label-error .q-picker-textfield-label {
    color: #f44336 !important;
  }

  select {
    -webkit-appearance: none;
    -moz-appearance: none;
    text-indent: 1px;
    text-overflow: '';
  }

  .label-success .q-picker-textfield:after, .label-error .q-picker-textfield:after {
    content: "" !important;
  }

  #android-preview {
    display: block;
    text-align: center;
    width: 467px;
    height: 800px;
    /*background: url('./statics/devices-sprite.jpg') 0 -800px no-repeat;*/
    background-size: 467px;
    margin: 5px auto 0;
  }

  #ios-preview {
    text-align: center;
    width: 467px;
    height: 800px;
    /*background: url('./statics/devices-sprite.jpg') center top no-repeat;*/
    background-size: 467px;
    margin: 5px auto 0;
  }

  #android-preview iframe {
    margin-top: 64px;
    width: 357px;
    height: 590px;
    background: #fff;
  }

  #ios-preview iframe {
    margin-top: 64px;
    width: 320px;
    height: 590px;
    background: #fff;
  }

  /*canvas {*/
    /*width: 270px !important;*/
  /*}*/

  @media only screen and (min-width: 601px) {
    .adv-form-one .timeline-badge {
      right: auto !important;
      left: auto !important;
    }

    .adv-form-one .timeline-content {
      margin-left: 3.9rem;
    }

    .adv-form-one .timeline-item {
      width: 100% !important;
    }

    .adv-form-one .timeline-title {
      text-align: inherit !important;
      margin-left: 3.9rem;
    }

    .timeline:before {
      left: 1.6rem;
    }
  }

  .adv-form-one .timeline-content .group .primary {
    display: none !important;
  }

  .underline {
    text-decoration: underline;
  }

  html,body {
    /*!*background-color: #324057;*!*/
    /*margin: 0px;*/
    /*padding: 0px;*/
    /*!*background: url(assets/bg1.jpg) center !important;*/
        /*background-size: cover;*!*/
    /*font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, SimSun, sans-serif;*/
    /*!*font-weight: 400;*!*/
    /*font-size: 14px !important;*/
    /*width: 100%;*/
    /*height: 100%;*/
    /*overflow:hidden;*/
    /*position:absolute;*/
    /*bottom:0px;*/
    /*left:0px;*/

    /*!*background: url(assets/bg.jpg) cover;*!*/
    /*-webkit-font-smoothing: antialiased;*/
    /*!*background: url('assets/bg.jpg');*!*/
    /*repeat: no-repeat;*/
    /*background-attachment: fixed;*/
    /*!*filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='assets/bg.jpg', sizingMethod='scale');*!*/
    /*!*-ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='assets/bg.jpg', sizingMethod='scale');*!*/
    /*background-size: cover;*/
    /*-moz-background-size: cover;*/
    /*-webkit-background-size: cover;*/

  }

  /*#app {*/
    /*position: absolute;*/
    /*top: 0px;*/
    /*bottom: 0px;*/
    /*width: 100%;*/

  /*}*/

  .layout {
    /*border: 1px solid #d7dde4;*/
    background: #f5f7f9;
    /*position: relative;*/
    /*border-radius: 4px;*/
    overflow: hidden;
    height: 100%;
    overflow-y: visible;
  }

  .layout-breadcrumb {
    background-color: #f5f7f9;
    padding: 10px 15px 0;
    height: 40px;
  }

  .layout-content {
    min-height: 400px;
    /*padding: 15px;*/
    overflow: auto;
    background: #fff;
    overflow: visible;
    min-height: 650px;
    /*border-radius: 4px;*/
    /*height: 90%;*/
  }

  .layout-content-main {
    /*padding: 10px;*/
    padding-top: 20px;
    padding-bottom: 20px;
  }
  .layout-content-body {
    padding: 20px;
  }

  .layout-copy {
    background-color: #f5f7f9;
    text-align: center;
    padding: 10px 0 20px;
    color: #9ea7b4;
    height: 5%;
  }

  .layout-menu-left {
    /*background: #009688;*/
    /*height: 100%;*/
  }

  .layout-right {
    background-color: white;
    /*height: 100%;*/
    /*width: 100%;*/

  }

  .layout-right-toggle {
    background-color: white;
    /*height: 100%;*/
    width: 100%;
    position: relative;
    top:0px;

  }

  .layout-header {
    height: 60px;
    background: #3097d1;
    /*box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);*/
  }

  .layout-logo-left {
    background: #3097d1;
    width: 100%;
    height: 60px;
    line-height: 60px;
    font-size: 24px;
    text-align: center;
    color: #657180;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
    /*  background: #5b6270;
      border-radius: 3px;
      margin: 15px auto;*/
  }

  .layout-logo-text {
    color: #ffffff;
    /*width: 100%;*/
    height: 60px;
    line-height: 60px;
    font-size: 24px;
    /*text-align: center;*/
    /*  background: #5b6270;
      border-radius: 3px;
      margin: 15px auto;*/
  }

  .layout-ceiling-main a {
    color: #9ba7b5;
  }

  .layout-hide-text .layout-text {
    /*display: none;*/
  }

  .ivu-col {
    transition: width .1s ease-in-out;
  }

  .ivu-row-flex {
    height: 100%;
  }

  .userinfo {
    display: inline-block;
    float: right;
    padding-right: 10px;
  }

  .userinfo .ivu-dropdown {
    margin-top: 50px;
  }

  .ivu-dropdown {
    margin-right: 25px;
    margin-top: 22px;
  }

  .ivu-menu-submenu-title {
    /*padding: 14px;*/
  }

  .head-img {
    width: 100%;
    height: 60px;
    line-height: 60px;
    float: right;
    margin-top: -50px;
  }

  .head-img img {
    border-radius: 20px;
    margin: 10px 0px 10px 10px;
    width: 40px;
    height: 40px;
    float: right;
  }

  .head-img2 {
    border-radius: 50px;
    padding: 20px;
    width: 100px;
    height: 100px;
    /*float: left;*/
  }

  #profile {
    height: 130px;
    background-color: #009688;
  }

  #user-name {
    left: 90px;
    bottom: 77px;
    position: relative;
    color: white;
    font-size: 18px;
    width: 129px;
  }

  #user-actions {
    left: 90px;
    bottom: 71px;
    position: relative;
    width: 171px;
  }

  .ivu-menu {
    /*padding-left: 20px;*/
  }

  .ivu-modal-header {
    background-color: #009688;
  }
</style>

